package com.ruoyi.ruoyiyinzheng.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.ruoyiyinzheng.domain.vo.StExperimentDatasViewVo;
import com.ruoyi.ruoyiyinzheng.domain.bo.StExperimentDatasViewBo;
import com.ruoyi.ruoyiyinzheng.service.IStExperimentDatasViewService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 全部实验数据控制器
 * 前端访问路由地址为:/ruoyiyinzheng/experimentDatasView
 *
 * @author ruoyi
 * @date 2023-11-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/experimentDatasView")
public class StExperimentDatasViewController extends BaseController {

    private final IStExperimentDatasViewService iStExperimentDatasViewService;

    /**
     * 查询全部实验数据列表
     */
    @GetMapping("/list")
    public TableDataInfo<StExperimentDatasViewVo> list(StExperimentDatasViewBo bo, PageQuery pageQuery) {
        return iStExperimentDatasViewService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出全部实验数据列表
     */
    @Log(title = "全部实验数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StExperimentDatasViewBo bo, HttpServletResponse response) {
        List<StExperimentDatasViewVo> list = iStExperimentDatasViewService.queryList(bo);
        ExcelUtil.exportExcel(list, "全部实验数据", StExperimentDatasViewVo.class, response);
    }

    /**
     * 获取全部实验数据详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<StExperimentDatasViewVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(iStExperimentDatasViewService.queryById(id));
    }

    /**
     * 新增全部实验数据
     */
    @Log(title = "全部实验数据", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StExperimentDatasViewBo bo) {
        return toAjax(iStExperimentDatasViewService.insertByBo(bo));
    }

    /**
     * 修改全部实验数据
     */
    @Log(title = "全部实验数据", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StExperimentDatasViewBo bo) {
        return toAjax(iStExperimentDatasViewService.updateByBo(bo));
    }

    /**
     * 删除全部实验数据
     *
     * @param ids 主键串
     */
    @Log(title = "全部实验数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iStExperimentDatasViewService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    @GetMapping(value = "/colorschemename/{ColorSchemeName}")
    public R<String> colorschemenamecount(@PathVariable("ColorSchemeName") String ColorSchemeName) {
        return R.ok(iStExperimentDatasViewService.selectColorSchemeNameCountById(ColorSchemeName));
    }

    @GetMapping(value = "/recieptname/{RecieptName}")
    public R<String> recieptnamecount(@PathVariable("RecieptName") String RecieptName) {
        return R.ok(iStExperimentDatasViewService.selectRecieptNameCountById(RecieptName));
    }
}
